/*
 * RFC 1321 compliant MD5 implementation,
 * by Christophe Devine <devine@cr0.net>;
 * this program is licensed under the GPL.
 */

#ifndef _MD5_H
#define _MD5_H

//#pragma warning(disable:4786)

#include <string>
using namespace std;

#define MD5_BUFF_LEN 33

typedef struct {
	unsigned long data[4]; 
}md5_t;
struct compare_md5_t
{
	bool operator()(const md5_t &d1, const md5_t &d2) const;
};


//
/*!
 * Manage md5.
 */
class md5
{
private:
	#define uint8  unsigned char
	#define uint32 unsigned long int

	struct md5_context
	{
		uint32 total[2];
		uint32 state[4];
		uint8 buffer[64];
	};

	void starts( struct md5_context *ctx );
	void process( struct md5_context *ctx, uint8 data[64] );
	void update( struct md5_context *ctx, uint8 *input, uint32 length );
	void finish( struct md5_context *ctx, uint8 digest[16] );

public:
	//! construct a CMD5 from any buffer
	void generate(unsigned char* buffer,int bufferlen);
	
	//! construct a CMD5 from any buffer, and put the md5 into provided string
	int generate(unsigned char* buffer, int bufferlen, char* md5, int md5len);
                   
	//! construct a CMD5
	md5();

	//! construct a md5src from char *
	md5(const char * md5src);

	//! construct a CMD5 from a 16 bytes md5
	md5(unsigned long* md5src);

	//! add a other md5
	md5 operator +(md5 adder);

	//! just if equal
	bool operator ==(md5 cmper);

	//! to a string
	string tostring();
	
	void getmd5_t(md5_t& md5_);	
private:
	unsigned long m_data[4];

};


extern md5 g_md5;
#endif /* md5.h */

